package com.xmy.aboutThread;

// 线程间通信，锁 线程同步
public class Demo3 {
    private static Object lock = new Object();

    static class ThreadA implements Runnable {

        @Override
        public void run() {
           synchronized (lock) {
               for (int i = 0; i < 50; i++) {
                   System.out.println("ThreadA " + i);
               }
           }
        }
    }

    static class ThreadB implements Runnable {
        @Override
        public void run() {
            synchronized (lock) {
                for (int i = 0; i < 50; i++) {
                    System.out.println("ThreadB " + i);
                }
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        new Thread(new ThreadA()).start();

        Thread.sleep(1000);

        new Thread(new ThreadB()).start();
    }
}
